package com.designmode.singleton;


/**
 * 1. 单例模式
 *
 * 双重检查，防止指令重排
 */
public class SingleInstance {

    private static volatile SingleInstance singleInstance;

    // 构造器私有化
    SingleInstance() {
    }

    public static SingleInstance getInstance() {
        if (singleInstance == null) {
            synchronized (SingleInstance.class) {
                if (singleInstance == null) {
                    singleInstance = new SingleInstance();
                }
            }
        }
        return singleInstance;
    }
}
